/**
 * Author: wangjunfu
 * Date: 2018-12-22
 * Description: 权限转移
 */

function permissionMove(pertype) {
    var selectids = "";

    $("input[type='checkbox']:checked").each(function () {
        if ($(this).val() !== "on") {
            selectids += $(this).val() + ",";
        }
    });

    if (selectids === "") {
        showInfoAlert("请至少选择一条记录进行操作！", null);
        return false;
    }

    $("#showMoveIds").text(selectids);
    $("#moveIds").val(selectids);
    $("#perType").val(pertype);

    $("#permission-move-modal").modal("show");
    onclickForSelect();
}

// ajax 绑定查询事件
function onclickForSelect() {
    $("input[aria-label='Search']").keyup(function () {
        var value = $("input[aria-label='Search']").val();

        ajax({
            url: '/basic/manage/getListForLike',
            data: {username: value},
            success: function (result) {
                var html = result.html;
                $("#username-select").empty();
                $("#username-select").append(html);
                $('#username-select').selectpicker('refresh');
            }
        });
    });
}

// 执行权限转移
function doPermissionMove() {
    var username = $('#username-select').find('option:selected').val();
    var moveids = $("#moveIds").val();
    var pertype = $("#perType").val();

    ajax({
        url: "/analysis/permission/permissionMove",
        type: "POST",
        data: {username: username, moveids: moveids, pertype: pertype},
        async: false,
        error: function (request) {
            showInfoAlert("服务器连接失败，请检查网络环境！", null);
        },
        success: function (result) {
            showInfoAlert(result.returnMessage, null);

            if (result.returnCode == 1){
                $("#permission-move-modal").modal("hide");
            }
        }
    });
}
